<?php
/** PAGE NOT ALLOWED
 * Verify if user called this page through a allowed page.
 * @message: That file cannot be displayed alone.
 */
  
if (!isset($allowed_page)) { echo "That file cannot be displayed alone."; exit; }
    
require_once("d5power.DAO.php");
	
/**
* Dotk NPC class.
*/
class NPC extends DAO {
	
	private $npc_id;
	private $name;
	private $str;
	private $dex;
	private $vit;
	private $int;
	private $money;
	private $agi;
	private $hp;
	private $avatar;
	private $map;
	private $posx;
	private $posy;
	
	
	//Getters and Setters
	public function getNpc_id() {
		return $this->npc_id;
	}
	
	public function setNpc_id($npc_id) {
		$this->npc_id = $npc_id;
	}
	
	public function getName() {
		return $this->name;
	}
	
	public function setName($name) {
		$this->name = $name;
	}
	
	public function getstr() {
		return $this->str;
	}
	
	public function setstr($str) {
		$this->str = $str;
	}
	
	public function getdex() {
		return $this->dex;
	}
	
	public function setdex($dex) {
		$this->dex = $dex;
	}
	
	public function getvit() {
		return $this->vit;
	}
	
	public function setvit($vit) {
		$this->vit = $vit;
	}
	
	public function getint() {
		return $this->int;
	}
	
	public function setint($int) {
		$this->int = $int;
	}
	
	public function getMoney() {
		return $this->money;
	}
	
	public function setMoney($money) {
		$this->money = $money;
	}
	
	public function getagi() {
		return $this->agi;
	}
	
	public function setagi($agi) {
		$this->agi = $agi;
	}
	
	public function getHp() {
		return $this->hp;
	}
	
	public function setHp($hp) {
		$this->hp = $hp;
	}
	
	public function getAvatar() {
		return $this->avatar;
	}
	
	public function setAvatar($avatar) {
		$this->avatar = $avatar;
	}
	
	public function load($npc_id) {
		$sql = "select
					npc_id, name, str, dex, vit, int, money, agi, hp, avatar
				from
					NPC
				where
					npc_id = ?";

		$result = $this->retrieve($sql, array($npc_id))->getRow();
		$this->npc_id = $result['npc_id'];
		$this->name = $result['name'];
		$this->str = $result['str'];
		$this->dex = $result['dex'];
		$this->vit = $result['vit'];
		$this->int = $result['int'];
		$this->money = $result['money'];
		$this->agi = $result['agi'];
		$this->hp = $result['hp'];
		$this->avatar = $result['avatar'];
		return $this;
	}
		
	/**
	*
	*/
	function create($name, $str, $dex, $vit, $int, $money, $agi, $hp, $avatar, $map, $posx, $posy, $gender) {
			
    	$sql = "insert into NPC 
					(name, str, dex, vit, int, money, agi, hp, avatar, map, posx, posy, gender) 
				values
					(?,?,?,?,?,?,?,?,?,?,?,?,?)";
        try {
			$this->retrieve($sql, array($name,$str,$dex,$vit,$int,$money,$agi,$hp,$avatar,$map,$posx,$posy,$gender));
			return true;
		}
		catch(Exception $e) {
		  return false;
		}
	}
	
	/**
	*
	*/
	public function save() {
		$sql = "update NPC set
					name= ?, str= ?, dex= ?, vit= ?, int= ?, money= ?, agi= ?, hp= ?, avatar= ?, map=?, posx=?, posy=? 
				where
					npc_id= ?";
			
		$playerResult = $this->retrieve($sql, array($this->name,$this->str,$this-> dex,$this-> vit,$this-> int,$this-> money, $this-> agi,$this-> HP,$this-> Avatar,$this->item_id));
	}
	  
	
	/**
	*
	*/
	public function delete() {
		$sql = "delete from NPC where npc_id = ? ";
		$playerResult = $this->retrieve($sql,array($this->npc_id));
	}	
	
}
	
  //Test unit	
  //$c = new NPC();
  //$c->setNpc_id(1);
  //print($c->create("Poring",3,1,12,12,12,12,12,1));
  //print($c->delete());
  
  ?>